package com.atguigu.gulimail.vo;



import java.math.BigDecimal;
import java.util.List;

/**
 * 购物车
 */
public class Cart {

    List<CartItem> items;

    private Integer countNum; //商品数量  比如同一个手机的数量是3

    private Integer countType;//商品类型  比如有三种商品类型/手机，电脑，笔记本。

    private BigDecimal totalAmount;     //商品总价

    private BigDecimal reduce=new BigDecimal("0.00");

    public List<CartItem> getItems() {
        return items;
    }

    public void setItems(List<CartItem> items) {
        this.items = items;
    }

    public Integer getCountNum() {
        countNum=0;
        if (items!=null&&items.size()>0){
            for (CartItem item : items) {
                countNum+=item.getCount();
            }
        }
        return countNum;
    }


    public Integer getCountType() {
        countType=0;
        if (items!=null&&items.size()>0){
            for (CartItem item : items) {
                countType+=1;
            }
        }

        return countType;
    }

    public BigDecimal getTotalAmount() {
        totalAmount=new BigDecimal(0);
        if (items!=null&&items.size()>0){
            for (CartItem item : items) {
                if (item.isCheck()){
            //如果商品选中了。计算价格。否则 不计算
                    totalAmount= totalAmount.add(item.getTotalPrice());
                }
            }
        }

        return totalAmount.subtract(this.reduce);
    }

    public BigDecimal getReduce() {
        return reduce;
    }

    public void setReduce(BigDecimal reduce) {
        this.reduce = reduce;
    }
}
